import {
    Component,
    OnInit,
    Injector,
    ViewChild,
    Output,
    EventEmitter,
    ElementRef,
    Input,
    ViewEncapsulation
} from '@angular/core';
import { AppComponentBase } from '@shared/common/app-component-base';
import {
    ListDtoExtensionsItem,
    Stock_TRBaseListDto,
    DataSourceType
} from '@shared/service-proxies/stock-service-proxies';
import { ModalDirective } from 'ngx-bootstrap';
import { finalize } from 'rxjs/operators';
import { LazyLoadEvent } from 'primeng/api';
import { Paginator } from 'primeng/primeng';
import { Table } from 'primeng/table';
import { appModuleAnimation } from '@shared/animations/routerTransition';

@Component({
    selector: 'toolingAccountRecordModal',
    templateUrl: './tooling-record-modal.component.html',
    animations: [appModuleAnimation()],
    encapsulation: ViewEncapsulation.None
})
export class ToolingAccountRecordModalComponent extends AppComponentBase {
    constructor(injector: Injector) {
        super(injector);
    }
    
    @ViewChild('createOrEditModal') modal: ModalDirective;
    @ViewChild('createOrEditModal') modalEl: ElementRef;
    @ViewChild('paginator') paginator: Paginator;
    @ViewChild('dataTable') dataTable: Table;
    _type: string;
    _handletype: string;
    anyncing = false;

    extensions: Array<ListDtoExtensionsItem>;

    active = false;
    saving = false;
    closed = false;
    billId = '';
    isShown = false;
    accountId = '';
    show(event): void {
        this.closed = false;
        this.modal.show();
        this.accountId = event.id;
        this.getData();
    }

    shown(): void {
        this.isShown = true;
        this.getRecordsIfNeeds(null);
    }

    getRecordsIfNeeds(event: LazyLoadEvent): void {
        if (!this.isShown) {
            return;
        }

        this.getData(event);
    }
    close(): void {
        //  this.active = false;
        this.modal.hide();
    }

    onHidden(event) {
        this.closed = true;
    }
 
    getData(event?: LazyLoadEvent) {
        if (this.primengTableHelper.shouldResetPaging(event) || event.first == undefined) {
            this.paginator.changePage(0);

            return;
        }

//         this.primengTableHelper.showLoadingIndicator();
// //getTRBaseListExtentionByAccountId
//         this._recordService
//             .getToolingTransRecordListByCode(
//                 this.accountId,
//                 undefined,
//                 this.primengTableHelper.getMaxResultCount(this.paginator, event),
//                 this.primengTableHelper.getSkipCount(this.paginator, event)
//             )
//             .subscribe(result => {
//                 this.extensions = result.items;
//                 this.primengTableHelper.totalRecordsCount = result.dtos.totalCount;
//                 this.primengTableHelper.records = result.dtos.items;
//                 this.primengTableHelper.hideLoadingIndicator();
//             });
    }
}
